#include "UIManager.h"
UIManager* UIManager::ui_manager =nullptr;
UIManager::UIManager(QObject *parent) : QObject(parent)
{
    now_task =nullptr;
}
void UIManager::run()
{
    qDebug() << "ui's thread is :" << QThread::currentThreadId();
//    Package::RegisterRequestSend package{"type","name","passwd","check_str","11111111111"};
    Package::LoginRequestSend package{"650476585","passwd"};
    emit sig_test(package);



}
void UIManager::addphone(QString phone){
    qDebug()<<"phone check start"<<phone;
    Package::ChecknumRequestSend package{phone};
//    ServerMessageAdapter::getInstance()->sendMessage(package);
    emit sig_phone_check(package);
}
void UIManager::addTaskLogin(QString uid,QString passwd)
{
    qDebug()<<"uid: "<<uid<<endl<<"passwd:"<<passwd;
//    if(str == "login")
//    this->now_task =
    Package::LoginRequestSend package{uid,passwd};
      emit sig_login(package);

}
void UIManager::LoginSuccess(QString name,QString uid_me,QString passwd)
{
    qDebug()<<"Login success";
    Account::getInstance()->login(name,uid_me,passwd);

}
void UIManager::registerRequest(QString phone,QString name,QString passwd,QString check_str)
{
    Package::RegisterRequestSend package{name,passwd,check_str,phone};
    emit sig_register(package);
}
void UIManager::addFriend(QString id_friend)
{
    QString uid_me;
    Account::getInstance()->getMyUid(uid_me);
    Package::AddFriendRequestSend package{id_friend,uid_me};

    emit sig_add_friend(package);
}
void UIManager::infoSyncRequest()
{
    emit sig_InfoSync();
    qDebug()<<"sig list sync";
}
void UIManager::sendMessage(QString id_friend,QString message)
{
    qDebug()<<"UI send ";
    QString uid_me;
    Account::getInstance()->getMyUid(uid_me);
    Package::MessageSend package{uid_me,id_friend,0,message};

    emit sig_send_msg(package);
}
void UIManager::sendMessageGroup(QString gid,QString uid,QString msg)
{
    qDebug()<<"UI send to group ";
    QString uid_me;
    Account::getInstance()->getMyUid(uid_me);
    Package::MessageSend package{uid_me,gid,0,msg};

    emit sig_send_msg(package);
}
void UIManager::msgSyncRequest(QString uid_group)
{
    qDebug()<<"msg sync request";
    Package::MessageHistoryRequestSend package{uid_group};

    emit sig_sync_msg(package);
}
void UIManager::agreeToGroup(QString uid,QString gid,bool is_agree)
{
    qDebug()<<"uid: "<<uid<<" gid: "<<gid;
    if(gid[0]=='-')
    {
        qDebug()<<"gid.toINT"<<gid.toInt();
        Package::AgreeToAddFriendStatus package{uid,is_agree};
        emit sig_agree_friend(package);

    }
    else
    {
        Package::AgreeToGroupStatus package{uid,gid,is_agree};
        emit sig_agree_group(package);
    }
}

void UIManager::createGroup()
{
    Package::CreateGroup package;
    emit sig_create_group(package);
}
